import modelExtend from 'dva-model-extend'
import { model } from 'models/common'
import { message } from 'antd'
import { routerRedux } from 'dva/router'
import queryString from 'query-string';
import { addArt,updateArt,artDetail} from 'services/article'


export default modelExtend(model, {
    namespace:'article',
    state:{
       tags:[],
    },
    effects:{
        //新增资讯
        *addArticle({payload},{call,put}){
            const hide = message.loading('保存中...');
            const data = yield call(addArt,payload);
            setTimeout(hide, 0);
            if(data.code == 0){
                yield put(routerRedux.push({
                    pathname:'/bshrecipes/articleList'
                }));
                message.success(data.msg)
            }else{
                message.error(data.msg)
            }
        },
        //更新资讯
        *updateArt({payload},{call,put}){
            const hide = message.loading('保存中...');
            const data = yield call(updateArt,payload);
            setTimeout(hide, 0);
            if(data.code == 0){
                yield put(routerRedux.push({
                    pathname:'/bshrecipes/articleList'
                }));
                message.success(data.msg);
            }else{
                message.error(data.msg);
            }
        }
    },
    reducers:{
        updateDetail(state,{payload}){
            return{
                ...state,
                detail:payload
            }
        },
        updateState(state,{payload}){
            return{
                ...state,
                tags:payload
            }
        }
    }
})